package com.dr.controller.admin;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dr.entity.Comment;
import com.dr.service.CommentService;
import com.dr.util.LayUiResult;


@Controller
@RequestMapping("/admin/")
public class CommentContorller{
	//注入service
	@Autowired
	private CommentService commentService;
	/**
	 * 全查
	 * @param p
	 * @return	以Map的方式返回查询到的数据和行数
	 */
	@RequestMapping(value = "/findComment.do",method = RequestMethod.GET)
	@ResponseBody//转为json格式数据
	public Map<String, Object> findComment(Comment c) {
		//调用service
		List<Comment> list = commentService.AllComment(c);
		int count = commentService.getCount(c);
		//返回结果都是以Map的方式返会给Layui所以返回值都是Map
		return LayUiResult.toClient("0", "succsee" , count, list);
	}
	/**
	 * 回复评论
	 * @param id	通过id回复
	 * @param reply
	 * @return
	 */
	@RequestMapping(value = "/updateComment.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> updateComment(int id, String reply) {
		// 调用service
		int res = commentService.updateComment(id, reply);
		// 返回结果
		return res > 0 ? LayUiResult.toClient("0", "回复成功") : LayUiResult.toClient("1", "回复失败");
	}
	@RequestMapping(value = "/deleteComment.do", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> deleteComment(int id) {
		// 调用service
		int res = commentService.deleteComment(id);
		// 返回结果
		return res > 0 ? LayUiResult.toClient("0", "删除成功") : LayUiResult.toClient("1", "删除失败");
	}
}
